/* eslint-disable no-unused-vars */
import Mock from 'mockjs';
import {
    getGlobalConfig,
    getDataset,
    getAggregateData,
    getDimensionValues
} from './data/index';
import {
    getPivotGlobalConfig,
    getPivotDataset,
    getPivotAggregateData
} from './data/pivot'

// 模拟保存cookie
Mock.XHR.prototype.withCredentials = true
Mock.setup({
    timeout: 300
})

Mock.mock(RegExp('/api/olap-board/board/get'), 'post', getPivotGlobalConfig)
Mock.mock(RegExp('/api/olap-data/dataset/getAggregateData'), 'post', getPivotAggregateData)
Mock.mock(RegExp('/api/olap-data/dataset/get'), 'post', getPivotDataset)

// Mock.mock(RegExp('/api/olap-board/board/get'), 'post', getGlobalConfig)
// Mock.mock(RegExp('/api/olap-data/dataset/getAggregateData'), 'post', getAggregateData)

Mock.mock(RegExp('/api/olap-data/dataset/getDimensionValues1'), 'post', getDimensionValues)
Mock.mock(RegExp('/api/olap-data/dataset/get'), 'post', getDataset)








// async function done() {
//     that.readyState = MockXMLHttpRequest.HEADERS_RECEIVED
//     that.dispatchEvent(new Event('readystatechange' /*, false, false, that*/ ))
//     that.readyState = MockXMLHttpRequest.LOADING
//     that.dispatchEvent(new Event('readystatechange' /*, false, false, that*/ ))

//     that.status = 200
//     that.statusText = HTTP_STATUS_CODES[200]

//     /**
//      * 【start】处理异步问题【huangteng】【2019-12-28】
//      */
//     const template = that.custom.template.template
//     if((typeof template === 'function') && (typeof template().then === 'function')) {
//         await template(that.custom.options).then(res=>{
//             that.custom.template.template = ()=> res
//         })
//     }
//     /**
//      * 【end】处理异步问题【huangteng】【2019-12-28】
//      */

//     // fix #92 #93 by @qddegtya
//     that.response = that.responseText = JSON.stringify(
//         convert(that.custom.template, that.custom.options),
//         null, 4
//     )
//     that.readyState = MockXMLHttpRequest.DONE
//     that.dispatchEvent(new Event('readystatechange' /*, false, false, that*/ ))
//     that.dispatchEvent(new Event('load' /*, false, false, that*/ ));
//     that.dispatchEvent(new Event('loadend' /*, false, false, that*/ ));
// }